#include "gameselect.h"
#include "gamehall.h"
#include "gameroom.h"

GameSelect::GameSelect(QWidget *parent) : QWidget(parent)
{
    //设置窗口大小
    this->setFixedSize(1200,800);
    this->setWindowIcon(QIcon(":res/ico.png"));
    this->setWindowTitle("关卡选择");

    QFont font("华文行楷",30);
    //放置按钮
    QPushButton *backBtn = new QPushButton(this);
    backBtn->move(1200 * 0.03,800 * 0.03);
    backBtn->setFixedSize(1200 * 0.05,800 * 0.05);
    backBtn->setIcon(QIcon(":res/back.png"));

    connect(backBtn,&QPushButton::clicked,[=](){
        //返回游戏大厅
        this->close();
        GameHall *gameHall = new GameHall;
        gameHall->show();
        QSound::play(":res/clicked.wav");//按钮点击加音效
    });

    //游戏模式 跳转 游戏房间 页面
    GameRoom *gameRoom = new GameRoom;

    QPushButton *simpleBtn = new QPushButton(this);
    simpleBtn->move(1200 * 0.1,800 * 0.8);
    simpleBtn->setText("简单模式");
    simpleBtn->setFont(font);
    simpleBtn->setStyleSheet("QPushButton{border:0px;}");
    connect(simpleBtn,&QPushButton::clicked,[=](){
        //简单模式
        this->close();
        gameRoom->setGeometry(this->geometry());
        gameRoom->show();
        QSound::play(":res/clicked.wav");//按钮点击加音效
    });


    QPushButton *normalBtn = new QPushButton(this);
    normalBtn->move(1200 * 0.3,800 * 0.8);
    normalBtn->setText("正常模式");
    normalBtn->setFont(font);
    normalBtn->setStyleSheet("QPushButton{border:0px;}");
    connect(normalBtn,&QPushButton::clicked,[=](){
        //正常模式
        this->close();
        gameRoom->setGeometry(this->geometry());
        gameRoom->show();
        QSound::play(":res/clicked.wav");//按钮点击加音效
    });

    QPushButton *complexBtn = new QPushButton(this);
    complexBtn->move(1200 * 0.5,800 * 0.8);
    complexBtn->setText("复杂模式");
    complexBtn->setFont(font);
    complexBtn->setStyleSheet("QPushButton{border:0px;}");
    connect(complexBtn,&QPushButton::clicked,[=](){
        //复杂模式
        this->close();
        gameRoom->setGeometry(this->geometry());
        gameRoom->show();
        QSound::play(":res/clicked.wav");//按钮点击加音效
    });

    QPushButton *hisBtn = new QPushButton(this);
    hisBtn->move(1200 * 0.7,800 * 0.8);
    hisBtn->setText("历史战绩");
    hisBtn->setFont(font);
    hisBtn->setStyleSheet("QPushButton{border:0px;}");
    connect(hisBtn,&QPushButton::clicked,[=](){
        QWidget *widget = new QWidget;
        widget->setWindowTitle("历史战绩");
        widget->setFixedSize(1200 * 0.4,800 * 0.4);
        widget->setWindowIcon(QIcon(":res/ico.png"));

        //历史战绩
        QTextEdit *edit = new QTextEdit(widget);//设计文本编辑器属性
        edit->setFont(font);
        edit->setFixedSize(1200 * 0.4,800 * 0.4);
        QFile file("D:/SHIMIR/Documents/SnakeGame/history.txt");//路径

        widget->show();
        QSound::play(":res/clicked.wav");//按钮点击加音效
    });
}

void GameSelect::paintEvent(QPaintEvent *event)
{
    QPainter painter(this);
    QPixmap pix(":res/game_select.png");
    painter.drawPixmap(0,0,this->width(),this->height(),pix);


}

